package com.ufinity.estimation.utils;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;

import com.cn.ufinity.common.log.Logger;
import com.cn.ufinity.common.log.LoggerFactory;


/**
 * bean name generate, delete "Impl" string
 * com.gene.crm.medicine.persistence.dao.hibernate.UserDaoImpl - > userDao
 * 
 * @author lxt
 * 
 */
public class MyBeanNameGenerator implements BeanNameGenerator {
	private Logger logger = LoggerFactory
			.getSystemLog(MyBeanNameGenerator.class);

	public String generateBeanName(BeanDefinition definition,
			BeanDefinitionRegistry registry) {
		String className = definition.getBeanClassName();
		
		int lastDot = className.lastIndexOf(".");
		int index = className.lastIndexOf("Impl");
		if (index != -1) {
			className = className.substring(lastDot + 1, className
					.lastIndexOf("Impl"));
		} else {
			className = className.substring(className.lastIndexOf(".") + 1);

		}
		className = className.substring(0, 1).toLowerCase()
				+ className.substring(1);
		logger.debug("generateBeanName", className + "=" + definition .getBeanClassName());
		return className;
	}

}
